﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="OrificeProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class OrificeProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.Orifice, BesAsm.MasterData.Entities.OrificeKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.OrificeKey key)
		{
			return Delete(transactionManager, key.OrificeId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_orificeId">Primary key, orifice ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _orificeId)
		{
			return Delete(null, _orificeId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeId">Primary key, orifice ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _orificeId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		FK_ORIFICES_LINKS Description: 
		/// </summary>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByLinkId(System.Int32? _linkId)
		{
			int count = -1;
			return GetByLinkId(_linkId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		FK_ORIFICES_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByLinkId(TransactionManager transactionManager, System.Int32? _linkId)
		{
			int count = -1;
			return GetByLinkId(transactionManager, _linkId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		FK_ORIFICES_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByLinkId(TransactionManager transactionManager, System.Int32? _linkId, int start, int pageLength)
		{
			int count = -1;
			return GetByLinkId(transactionManager, _linkId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		fkOrificesLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByLinkId(System.Int32? _linkId, int start, int pageLength)
		{
			int count =  -1;
			return GetByLinkId(null, _linkId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		fkOrificesLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByLinkId(System.Int32? _linkId, int start, int pageLength,out int count)
		{
			return GetByLinkId(null, _linkId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_LINKS key.
		///		FK_ORIFICES_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS.  Indicates the link along which the orifice will be placed.  The link must have its us_node_id match the record's us_node_id.  If this field is empty, ds_node_id must not be empty.    If both are not empty, ds_node_id overrides.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByLinkId(TransactionManager transactionManager, System.Int32? _linkId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		FK_ORIFICES_NODES_DS Description: 
		/// </summary>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByDsNodeId(System.Int32? _dsNodeId)
		{
			int count = -1;
			return GetByDsNodeId(_dsNodeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		FK_ORIFICES_NODES_DS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByDsNodeId(TransactionManager transactionManager, System.Int32? _dsNodeId)
		{
			int count = -1;
			return GetByDsNodeId(transactionManager, _dsNodeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		FK_ORIFICES_NODES_DS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByDsNodeId(TransactionManager transactionManager, System.Int32? _dsNodeId, int start, int pageLength)
		{
			int count = -1;
			return GetByDsNodeId(transactionManager, _dsNodeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		fkOrificesNodesDs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByDsNodeId(System.Int32? _dsNodeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByDsNodeId(null, _dsNodeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		fkOrificesNodesDs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByDsNodeId(System.Int32? _dsNodeId, int start, int pageLength,out int count)
		{
			return GetByDsNodeId(null, _dsNodeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_DS key.
		///		FK_ORIFICES_NODES_DS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dsNodeId">Downstream node ID, foreign key to NODES. If empty, then the link_id must not be empty.  If both aren't empty, then this overrides.   If both are not empty, ds_node_id overrides.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByDsNodeId(TransactionManager transactionManager, System.Int32? _dsNodeId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		FK_ORIFICES_NODES_US Description: 
		/// </summary>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByUsNodeId(System.Int32 _usNodeId)
		{
			int count = -1;
			return GetByUsNodeId(_usNodeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		FK_ORIFICES_NODES_US Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByUsNodeId(TransactionManager transactionManager, System.Int32 _usNodeId)
		{
			int count = -1;
			return GetByUsNodeId(transactionManager, _usNodeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		FK_ORIFICES_NODES_US Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByUsNodeId(TransactionManager transactionManager, System.Int32 _usNodeId, int start, int pageLength)
		{
			int count = -1;
			return GetByUsNodeId(transactionManager, _usNodeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		fkOrificesNodesUs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByUsNodeId(System.Int32 _usNodeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByUsNodeId(null, _usNodeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		fkOrificesNodesUs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByUsNodeId(System.Int32 _usNodeId, int start, int pageLength,out int count)
		{
			return GetByUsNodeId(null, _usNodeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_NODES_US key.
		///		FK_ORIFICES_NODES_US Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_usNodeId">Upstream node ID, foreign key to NODES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByUsNodeId(TransactionManager transactionManager, System.Int32 _usNodeId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		FK_ORIFICES_ORIFICE_SHAPES Description: 
		/// </summary>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeShapeId(System.String _orificeShapeId)
		{
			int count = -1;
			return GetByOrificeShapeId(_orificeShapeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		FK_ORIFICES_ORIFICE_SHAPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByOrificeShapeId(TransactionManager transactionManager, System.String _orificeShapeId)
		{
			int count = -1;
			return GetByOrificeShapeId(transactionManager, _orificeShapeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		FK_ORIFICES_ORIFICE_SHAPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeShapeId(TransactionManager transactionManager, System.String _orificeShapeId, int start, int pageLength)
		{
			int count = -1;
			return GetByOrificeShapeId(transactionManager, _orificeShapeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		fkOrificesOrificeShapes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeShapeId(System.String _orificeShapeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByOrificeShapeId(null, _orificeShapeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		fkOrificesOrificeShapes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeShapeId(System.String _orificeShapeId, int start, int pageLength,out int count)
		{
			return GetByOrificeShapeId(null, _orificeShapeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_SHAPES key.
		///		FK_ORIFICES_ORIFICE_SHAPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeShapeId">Foreign key to ORIFICE_SHAPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByOrificeShapeId(TransactionManager transactionManager, System.String _orificeShapeId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		FK_ORIFICES_ORIFICE_TYPES Description: 
		/// </summary>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeTypeId(System.String _orificeTypeId)
		{
			int count = -1;
			return GetByOrificeTypeId(_orificeTypeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		FK_ORIFICES_ORIFICE_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByOrificeTypeId(TransactionManager transactionManager, System.String _orificeTypeId)
		{
			int count = -1;
			return GetByOrificeTypeId(transactionManager, _orificeTypeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		FK_ORIFICES_ORIFICE_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeTypeId(TransactionManager transactionManager, System.String _orificeTypeId, int start, int pageLength)
		{
			int count = -1;
			return GetByOrificeTypeId(transactionManager, _orificeTypeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		fkOrificesOrificeTypes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeTypeId(System.String _orificeTypeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByOrificeTypeId(null, _orificeTypeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		fkOrificesOrificeTypes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByOrificeTypeId(System.String _orificeTypeId, int start, int pageLength,out int count)
		{
			return GetByOrificeTypeId(null, _orificeTypeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_ORIFICE_TYPES key.
		///		FK_ORIFICES_ORIFICE_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeTypeId">Foreign key to ORIFICE_TYPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByOrificeTypeId(TransactionManager transactionManager, System.String _orificeTypeId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		FK_ORIFICES_STATUSES Description: 
		/// </summary>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByStatus(System.String _status)
		{
			int count = -1;
			return GetByStatus(_status, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		FK_ORIFICES_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		/// <remarks></remarks>
		public TList<Orifice> GetByStatus(TransactionManager transactionManager, System.String _status)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		FK_ORIFICES_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		fkOrificesStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByStatus(System.String _status, int start, int pageLength)
		{
			int count =  -1;
			return GetByStatus(null, _status, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		fkOrificesStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public TList<Orifice> GetByStatus(System.String _status, int start, int pageLength,out int count)
		{
			return GetByStatus(null, _status, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ORIFICES_STATUSES key.
		///		FK_ORIFICES_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.Orifice objects.</returns>
		public abstract TList<Orifice> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.Orifice Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.OrificeKey key, int start, int pageLength)
		{
			return GetByOrificeId(transactionManager, key.OrificeId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_ORIFICES index.
		/// </summary>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public BesAsm.MasterData.Entities.Orifice GetByOrificeId(System.Int32 _orificeId)
		{
			int count = -1;
			return GetByOrificeId(null,_orificeId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ORIFICES index.
		/// </summary>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public BesAsm.MasterData.Entities.Orifice GetByOrificeId(System.Int32 _orificeId, int start, int pageLength)
		{
			int count = -1;
			return GetByOrificeId(null, _orificeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ORIFICES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public BesAsm.MasterData.Entities.Orifice GetByOrificeId(TransactionManager transactionManager, System.Int32 _orificeId)
		{
			int count = -1;
			return GetByOrificeId(transactionManager, _orificeId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ORIFICES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public BesAsm.MasterData.Entities.Orifice GetByOrificeId(TransactionManager transactionManager, System.Int32 _orificeId, int start, int pageLength)
		{
			int count = -1;
			return GetByOrificeId(transactionManager, _orificeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ORIFICES index.
		/// </summary>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public BesAsm.MasterData.Entities.Orifice GetByOrificeId(System.Int32 _orificeId, int start, int pageLength, out int count)
		{
			return GetByOrificeId(null, _orificeId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ORIFICES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_orificeId">Primary key, orifice ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Orifice"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.Orifice GetByOrificeId(TransactionManager transactionManager, System.Int32 _orificeId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Orifice&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Orifice&gt;"/></returns>
		public static TList<Orifice> Fill(IDataReader reader, TList<Orifice> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.Orifice c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Orifice")
					.Append("|").Append((System.Int32)reader[((int)OrificeColumn.OrificeId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Orifice>(
					key.ToString(), // EntityTrackingKey
					"Orifice",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.Orifice();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.OrificeId = (System.Int32)reader[((int)OrificeColumn.OrificeId - 1)];
					c.OriginalOrificeId = c.OrificeId;
					c.OrificeName = (reader.IsDBNull(((int)OrificeColumn.OrificeName - 1)))?null:(System.String)reader[((int)OrificeColumn.OrificeName - 1)];
					c.UsNodeId = (System.Int32)reader[((int)OrificeColumn.UsNodeId - 1)];
					c.DsNodeId = (reader.IsDBNull(((int)OrificeColumn.DsNodeId - 1)))?null:(System.Int32?)reader[((int)OrificeColumn.DsNodeId - 1)];
					c.LinkId = (reader.IsDBNull(((int)OrificeColumn.LinkId - 1)))?null:(System.Int32?)reader[((int)OrificeColumn.LinkId - 1)];
					c.OrificeTypeId = (System.String)reader[((int)OrificeColumn.OrificeTypeId - 1)];
					c.OrificeShapeId = (System.String)reader[((int)OrificeColumn.OrificeShapeId - 1)];
					c.OrificeArea = (System.Decimal)reader[((int)OrificeColumn.OrificeArea - 1)];
					c.Height = (reader.IsDBNull(((int)OrificeColumn.Height - 1)))?null:(System.Decimal?)reader[((int)OrificeColumn.Height - 1)];
					c.Invert = (reader.IsDBNull(((int)OrificeColumn.Invert - 1)))?null:(System.Decimal?)reader[((int)OrificeColumn.Invert - 1)];
					c.Coefficient = (System.Decimal)reader[((int)OrificeColumn.Coefficient - 1)];
					c.EditedBy = (System.String)reader[((int)OrificeColumn.EditedBy - 1)];
					c.EditReason = (System.String)reader[((int)OrificeColumn.EditReason - 1)];
					c.Status = (System.String)reader[((int)OrificeColumn.Status - 1)];
					c.AppendDate = (System.DateTime)reader[((int)OrificeColumn.AppendDate - 1)];
					c.EditDate = (reader.IsDBNull(((int)OrificeColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)OrificeColumn.EditDate - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.Orifice"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Orifice"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.Orifice entity)
		{
			if (!reader.Read()) return;
			
			entity.OrificeId = (System.Int32)reader[((int)OrificeColumn.OrificeId - 1)];
			entity.OriginalOrificeId = (System.Int32)reader["orifice_id"];
			entity.OrificeName = (reader.IsDBNull(((int)OrificeColumn.OrificeName - 1)))?null:(System.String)reader[((int)OrificeColumn.OrificeName - 1)];
			entity.UsNodeId = (System.Int32)reader[((int)OrificeColumn.UsNodeId - 1)];
			entity.DsNodeId = (reader.IsDBNull(((int)OrificeColumn.DsNodeId - 1)))?null:(System.Int32?)reader[((int)OrificeColumn.DsNodeId - 1)];
			entity.LinkId = (reader.IsDBNull(((int)OrificeColumn.LinkId - 1)))?null:(System.Int32?)reader[((int)OrificeColumn.LinkId - 1)];
			entity.OrificeTypeId = (System.String)reader[((int)OrificeColumn.OrificeTypeId - 1)];
			entity.OrificeShapeId = (System.String)reader[((int)OrificeColumn.OrificeShapeId - 1)];
			entity.OrificeArea = (System.Decimal)reader[((int)OrificeColumn.OrificeArea - 1)];
			entity.Height = (reader.IsDBNull(((int)OrificeColumn.Height - 1)))?null:(System.Decimal?)reader[((int)OrificeColumn.Height - 1)];
			entity.Invert = (reader.IsDBNull(((int)OrificeColumn.Invert - 1)))?null:(System.Decimal?)reader[((int)OrificeColumn.Invert - 1)];
			entity.Coefficient = (System.Decimal)reader[((int)OrificeColumn.Coefficient - 1)];
			entity.EditedBy = (System.String)reader[((int)OrificeColumn.EditedBy - 1)];
			entity.EditReason = (System.String)reader[((int)OrificeColumn.EditReason - 1)];
			entity.Status = (System.String)reader[((int)OrificeColumn.Status - 1)];
			entity.AppendDate = (System.DateTime)reader[((int)OrificeColumn.AppendDate - 1)];
			entity.EditDate = (reader.IsDBNull(((int)OrificeColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)OrificeColumn.EditDate - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.Orifice"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Orifice"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.Orifice entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.OrificeId = (System.Int32)dataRow["orifice_id"];
			entity.OriginalOrificeId = (System.Int32)dataRow["orifice_id"];
			entity.OrificeName = Convert.IsDBNull(dataRow["orifice_name"]) ? null : (System.String)dataRow["orifice_name"];
			entity.UsNodeId = (System.Int32)dataRow["us_node_id"];
			entity.DsNodeId = Convert.IsDBNull(dataRow["ds_node_id"]) ? null : (System.Int32?)dataRow["ds_node_id"];
			entity.LinkId = Convert.IsDBNull(dataRow["link_id"]) ? null : (System.Int32?)dataRow["link_id"];
			entity.OrificeTypeId = (System.String)dataRow["orifice_type_id"];
			entity.OrificeShapeId = (System.String)dataRow["orifice_shape_id"];
			entity.OrificeArea = (System.Decimal)dataRow["orifice_area"];
			entity.Height = Convert.IsDBNull(dataRow["height"]) ? null : (System.Decimal?)dataRow["height"];
			entity.Invert = Convert.IsDBNull(dataRow["invert"]) ? null : (System.Decimal?)dataRow["invert"];
			entity.Coefficient = (System.Decimal)dataRow["coefficient"];
			entity.EditedBy = (System.String)dataRow["edited_by"];
			entity.EditReason = (System.String)dataRow["edit_reason"];
			entity.Status = (System.String)dataRow["status"];
			entity.AppendDate = (System.DateTime)dataRow["append_date"];
			entity.EditDate = Convert.IsDBNull(dataRow["edit_date"]) ? null : (System.DateTime?)dataRow["edit_date"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Orifice"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.Orifice Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.Orifice entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region LinkIdSource	
			if (CanDeepLoad(entity, "Link|LinkIdSource", deepLoadType, innerList) 
				&& entity.LinkIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.LinkId ?? (int)0);
				Link tmpEntity = EntityManager.LocateEntity<Link>(EntityLocator.ConstructKeyFromPkItems(typeof(Link), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.LinkIdSource = tmpEntity;
				else
					entity.LinkIdSource = DataRepository.LinkProvider.GetByLinkId(transactionManager, (entity.LinkId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LinkIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.LinkIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.LinkProvider.DeepLoad(transactionManager, entity.LinkIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion LinkIdSource

			#region DsNodeIdSource	
			if (CanDeepLoad(entity, "Node|DsNodeIdSource", deepLoadType, innerList) 
				&& entity.DsNodeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.DsNodeId ?? (int)0);
				Node tmpEntity = EntityManager.LocateEntity<Node>(EntityLocator.ConstructKeyFromPkItems(typeof(Node), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.DsNodeIdSource = tmpEntity;
				else
					entity.DsNodeIdSource = DataRepository.NodeProvider.GetByNodeId(transactionManager, (entity.DsNodeId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DsNodeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.DsNodeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NodeProvider.DeepLoad(transactionManager, entity.DsNodeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion DsNodeIdSource

			#region UsNodeIdSource	
			if (CanDeepLoad(entity, "Node|UsNodeIdSource", deepLoadType, innerList) 
				&& entity.UsNodeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.UsNodeId;
				Node tmpEntity = EntityManager.LocateEntity<Node>(EntityLocator.ConstructKeyFromPkItems(typeof(Node), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.UsNodeIdSource = tmpEntity;
				else
					entity.UsNodeIdSource = DataRepository.NodeProvider.GetByNodeId(transactionManager, entity.UsNodeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'UsNodeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.UsNodeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NodeProvider.DeepLoad(transactionManager, entity.UsNodeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion UsNodeIdSource

			#region OrificeShapeIdSource	
			if (CanDeepLoad(entity, "OrificeShape|OrificeShapeIdSource", deepLoadType, innerList) 
				&& entity.OrificeShapeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.OrificeShapeId;
				OrificeShape tmpEntity = EntityManager.LocateEntity<OrificeShape>(EntityLocator.ConstructKeyFromPkItems(typeof(OrificeShape), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.OrificeShapeIdSource = tmpEntity;
				else
					entity.OrificeShapeIdSource = DataRepository.OrificeShapeProvider.GetByOrificeShapeId(transactionManager, entity.OrificeShapeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'OrificeShapeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.OrificeShapeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.OrificeShapeProvider.DeepLoad(transactionManager, entity.OrificeShapeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion OrificeShapeIdSource

			#region OrificeTypeIdSource	
			if (CanDeepLoad(entity, "OrificeType|OrificeTypeIdSource", deepLoadType, innerList) 
				&& entity.OrificeTypeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.OrificeTypeId;
				OrificeType tmpEntity = EntityManager.LocateEntity<OrificeType>(EntityLocator.ConstructKeyFromPkItems(typeof(OrificeType), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.OrificeTypeIdSource = tmpEntity;
				else
					entity.OrificeTypeIdSource = DataRepository.OrificeTypeProvider.GetByOrificeTypeId(transactionManager, entity.OrificeTypeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'OrificeTypeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.OrificeTypeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.OrificeTypeProvider.DeepLoad(transactionManager, entity.OrificeTypeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion OrificeTypeIdSource

			#region StatusSource	
			if (CanDeepLoad(entity, "Status|StatusSource", deepLoadType, innerList) 
				&& entity.StatusSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.Status;
				Status tmpEntity = EntityManager.LocateEntity<Status>(EntityLocator.ConstructKeyFromPkItems(typeof(Status), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.StatusSource = tmpEntity;
				else
					entity.StatusSource = DataRepository.StatusProvider.GetByStatusId(transactionManager, entity.Status);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StatusSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.StatusSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.StatusProvider.DeepLoad(transactionManager, entity.StatusSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion StatusSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.Orifice object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.Orifice instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.Orifice Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.Orifice entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region LinkIdSource
			if (CanDeepSave(entity, "Link|LinkIdSource", deepSaveType, innerList) 
				&& entity.LinkIdSource != null)
			{
				DataRepository.LinkProvider.Save(transactionManager, entity.LinkIdSource);
				entity.LinkId = entity.LinkIdSource.LinkId;
			}
			#endregion 
			
			#region DsNodeIdSource
			if (CanDeepSave(entity, "Node|DsNodeIdSource", deepSaveType, innerList) 
				&& entity.DsNodeIdSource != null)
			{
				DataRepository.NodeProvider.Save(transactionManager, entity.DsNodeIdSource);
				entity.DsNodeId = entity.DsNodeIdSource.NodeId;
			}
			#endregion 
			
			#region UsNodeIdSource
			if (CanDeepSave(entity, "Node|UsNodeIdSource", deepSaveType, innerList) 
				&& entity.UsNodeIdSource != null)
			{
				DataRepository.NodeProvider.Save(transactionManager, entity.UsNodeIdSource);
				entity.UsNodeId = entity.UsNodeIdSource.NodeId;
			}
			#endregion 
			
			#region OrificeShapeIdSource
			if (CanDeepSave(entity, "OrificeShape|OrificeShapeIdSource", deepSaveType, innerList) 
				&& entity.OrificeShapeIdSource != null)
			{
				DataRepository.OrificeShapeProvider.Save(transactionManager, entity.OrificeShapeIdSource);
				entity.OrificeShapeId = entity.OrificeShapeIdSource.OrificeShapeId;
			}
			#endregion 
			
			#region OrificeTypeIdSource
			if (CanDeepSave(entity, "OrificeType|OrificeTypeIdSource", deepSaveType, innerList) 
				&& entity.OrificeTypeIdSource != null)
			{
				DataRepository.OrificeTypeProvider.Save(transactionManager, entity.OrificeTypeIdSource);
				entity.OrificeTypeId = entity.OrificeTypeIdSource.OrificeTypeId;
			}
			#endregion 
			
			#region StatusSource
			if (CanDeepSave(entity, "Status|StatusSource", deepSaveType, innerList) 
				&& entity.StatusSource != null)
			{
				DataRepository.StatusProvider.Save(transactionManager, entity.StatusSource);
				entity.Status = entity.StatusSource.StatusId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region OrificeChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.Orifice</c>
	///</summary>
	public enum OrificeChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Link</c> at LinkIdSource
		///</summary>
		[ChildEntityType(typeof(Link))]
		Link,
			
		///<summary>
		/// Composite Property for <c>Node</c> at DsNodeIdSource
		///</summary>
		[ChildEntityType(typeof(Node))]
		Node,
			
		///<summary>
		/// Composite Property for <c>OrificeShape</c> at OrificeShapeIdSource
		///</summary>
		[ChildEntityType(typeof(OrificeShape))]
		OrificeShape,
			
		///<summary>
		/// Composite Property for <c>OrificeType</c> at OrificeTypeIdSource
		///</summary>
		[ChildEntityType(typeof(OrificeType))]
		OrificeType,
			
		///<summary>
		/// Composite Property for <c>Status</c> at StatusSource
		///</summary>
		[ChildEntityType(typeof(Status))]
		Status,
		}
	
	#endregion OrificeChildEntityTypes
	
	#region OrificeFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;OrificeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Orifice"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class OrificeFilterBuilder : SqlFilterBuilder<OrificeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the OrificeFilterBuilder class.
		/// </summary>
		public OrificeFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the OrificeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public OrificeFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the OrificeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public OrificeFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion OrificeFilterBuilder
	
	#region OrificeParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;OrificeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Orifice"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class OrificeParameterBuilder : ParameterizedSqlFilterBuilder<OrificeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the OrificeParameterBuilder class.
		/// </summary>
		public OrificeParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the OrificeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public OrificeParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the OrificeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public OrificeParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion OrificeParameterBuilder
	
	#region OrificeSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;OrificeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Orifice"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class OrificeSortBuilder : SqlSortBuilder<OrificeColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the OrificeSqlSortBuilder class.
		/// </summary>
		public OrificeSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion OrificeSortBuilder
	
} // end namespace
